package com.yy.controller;

import com.yy.domain.Area;
import com.yy.model.Result;
import com.yy.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "区域管理相关接口")
@RequestMapping("admin/area")
public class AreaController {

    @Autowired
    private AreaService areaService;

    @GetMapping("list")
    @ApiOperation("全查询区域列表")
    @PreAuthorize("hasAuthority('admin:area:list')")
    public Result<List<Area>> loadAreaList() {
        List<Area> areaList = areaService.list();
        return Result.success(areaList);
    }

    @GetMapping("listByPid")
    @ApiOperation("根据父id查询子区域列表")
    public Result<List<Area>> loadAreasByPid(Long pid) {
        List<Area> areaList = areaService.loadAreasByPid(pid);
        return Result.success(areaList);
    }






}
